
const { serverError } = require('../../utils');
const { emptyCheck } = require("../../utils/checkEmpty");
const { setCateAddProductController,
    setCanelCateRelationProdController } = require('../../controller/relation/relation.CONTROLLER');

const router = require('koa-router')()
router.prefix('/relation')

/**@description 产品批量设置分类 */
// router.post("/setProductAddCates", async (ctx, next) => {
//     try {
//         const { productIds, categoryId } = ctx.request.body;
//         const check = emptyCheck({ productIds, categoryId })
//         if (check.code!== 0) {
//             ctx.body = check
//             return;
//         }

//         const res = await saveCateForProduct({
//             productId, categoryId
//         })
//         ctx.body = res
//     } catch (error) {
//         console.log("错误", error)
//     }
// })



/**@description 分类批量添加产品 暂仅支持一个商品1个分类，一个分类下有可以有多个商品 */
router.post("/setCateAddProducts", async (ctx, next) => {
    try {
        const { categoryId, productIds = [] } = ctx.request.body;
        const res = await setCateAddProductController({ categoryId, productIds });
        ctx.body = res;
    } catch (error) {
        ctx.body = serverError;
    }
})

/**@description 取消产品和分类的关联关系 */
router.post("/setCancelProductAndCate", async (ctx, next) => {
    try {
        const { categoryId, productIds = [] } = ctx.request.body;
        const res = await setCanelCateRelationProdController({ categoryId, productIds });
        ctx.body = res;
    } catch (error) {
        ctx.body = serverError;
    }
})


module.exports = router;